package com.why.simpleboot.core.core.aop.processor;

import com.why.simpleboot.core.core.aop.interceptor.Interceptor;
import com.why.simpleboot.core.core.config.BeanPostProcessor;

import java.util.List;

/**
 * @program: why-simpleboot-framework
 * @description: 该类仅仅完成对拦截器的遍历，真正的warpper方法交给子类去实现
 * @author: @why
 * @create: 2021-05-27 13:18
 **/
public abstract class AbstractAopBeanPostProcessor implements BeanPostProcessor {

    List<Interceptor> interceptors;

    public AbstractAopBeanPostProcessor(List<Interceptor> interceptors) {
        this.interceptors = interceptors;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean) {
        Object wrapperBean = bean;
        for (Interceptor interceptor : interceptors) {
            if (interceptor.supported(bean)) {
                wrapperBean = wrappedBean(wrapperBean,interceptor);
            }
        }
        return wrapperBean;

    }

    public abstract Object wrappedBean(Object bean, Interceptor interceptor);
}
